﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMSConsulting.SMSLIB.Utilities;
using System.Runtime.InteropServices;

namespace Access.PowerTools.AbstractionLayer
{
    public class AccessApplication
    {
        private object _hostApplicationBridge;
        private IHostComunicationBridge _iHost;
        public AccessApplication()
        {
            _hostApplicationBridge = Access.PowerTools.Settings.Globals.HostApplication;
            _iHost = _hostApplicationBridge as IHostComunicationBridge;
        }
        public void Terminate()
        {
            if (_hostApplicationBridge != null)
                Marshal.ReleaseComObject(_hostApplicationBridge);
            _hostApplicationBridge = null;
            _iHost = null;
        }


        public string Name { get { return _iHost.ApplicationName; }}

        public string Version { get { return _iHost.ApplicationVersion; }}

        public AccessDatabase CurrentDatabase { get { return _iHost.CurrentDatabase; }}

        public void SaveAsText(
                     AccessDataBaseObjectTypeEnumeration objectType,
                     string objectName,
                     string backUpFileFullPath)
        {
            _iHost.SaveAsText(objectType, objectName, backUpFileFullPath);     
        }

        public void LoadFromText(
                 AccessDataBaseObjectTypeEnumeration objectType,
                 string objectName,
                 string backUpFileFullPath)
        {
            _iHost.LoadFromText(objectType, objectName, backUpFileFullPath);   
        }

        public bool StartHostApplication() 
        { 
            return _iHost.StartHostApplication(); 
        }
        
        public bool QuitHostApplication() 
        { 
            return _iHost.QuitHostApplication(); 
        }
        
        public bool OpenCurrentDatabase(string databaseFullPath) 
        { 
            return _iHost.OpenCurrentDatabase(databaseFullPath); 
        }
        
        public bool CloseCurrentDatabase() 
        { 
            return _iHost.CloseCurrentDatabase(); 
        }

        public bool CompactCurrentDatabase() 
        { 
            return _iHost.CompactCurrentDatabase(); 
        }

    }
}
